import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
import WelcomePage from './views/WelcomePage'
import login from './components/common/Login'
import signUp from './components/common/SignUp'
import Dash from './views/DashBoard'
import cookie from 'vue-cookie'
Vue.use(Router);


var mainRoutes={
        path: '/',
        redirect:'/dashBoard',
        name: 'home',
        component: Home,
        children:[

            {
                path: 'dashBoard',
                name:  'dashBoard',
                component: Dash,
                description:'消息看板',
                groupIndex:0,
            },
            {
                path: 'download',
                name: 'download',
                component:()=> import('./views/business/Download.vue'),
                description: '文件下载',
                groupIndex: 1,
            },
            {
                path: 'upload',
                name: 'upload',
                component:()=> import('./views/business/Upload.vue'),
                description: '文件上传',
                groupIndex: 1,
            },
            {
                path: 'chat',
                name: 'chat',
                component:()=> import('./views/business/Chat.vue'),
                description: '聊天室',
                groupIndex: 2,
            }
        ]
    };
export {mainRoutes};
var router =new Router({
    routes: [
        mainRoutes,
        {
            path: '/welcome',
            redirect:'/welcome/login',
            name: 'welcome',
            component: WelcomePage,
            part: 1,
            children: [
                {
                    path: 'login',
                    name: 'login',
                    component: login,
                    group: 1
                },
                {
                    path: 'signUp',
                    name: 'signUp',
                    component: signUp,
                    group: 1
                },
            ]
        },


    ]
});
function getCookieValue(keyword){
    var listString = document.cookie.split("; ");
    for (let i = 0; i <listString.length ; i++) {
        let point = listString.split('=');
        if (point[0]==keyword){
            return point[1];
        }
        return null;

    }
}
router.beforeEach((to, from, next) => {
  // if (getCookieValue('JSESSIONID')===null){
  //     next({
  //         path:'/welcome/login'
  //     })
  // }
  // console.log(getCookieValue('JSESSIONID'));
  next();
});

export default router;
